package com.welson.restfultoolx.model;

import java.util.Objects;

/**
 * 参数信息模型
 * 存储Controller方法参数的详细信息
 */
public class ParamInfo {
    private String name;           // 参数名
    private String type;           // 参数类型
    private boolean required;      // 是否必需
    private String defaultValue;   // 默认值
    private String description;    // 参数描述
    private String annotation;     // 参数注解（如@RequestParam, @PathVariable等）

    public ParamInfo() {
    }

    public ParamInfo(String name, String type) {
        this.name = name;
        this.type = type;
        this.required = false;
    }

    public ParamInfo(String name, String type, boolean required) {
        this.name = name;
        this.type = type;
        this.required = required;
    }

    // Getters and Setters
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public boolean isRequired() {
        return required;
    }

    public void setRequired(boolean required) {
        this.required = required;
    }

    public String getDefaultValue() {
        return defaultValue;
    }

    public void setDefaultValue(String defaultValue) {
        this.defaultValue = defaultValue;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getAnnotation() {
        return annotation;
    }

    public void setAnnotation(String annotation) {
        this.annotation = annotation;
    }

    /**
     * 获取参数的简短类型名（不包含包名）
     */
    public String getSimpleType() {
        if (type == null) {
            return "";
        }
        int lastDot = type.lastIndexOf('.');
        return lastDot >= 0 ? type.substring(lastDot + 1) : type;
    }

    /**
     * 获取参数的完整描述
     */
    public String getFullDescription() {
        StringBuilder sb = new StringBuilder();
        if (annotation != null && !annotation.isEmpty()) {
            sb.append(annotation).append(" ");
        }
        sb.append(getSimpleType()).append(" ").append(name);
        if (required) {
            sb.append(" (required)");
        }
        if (defaultValue != null && !defaultValue.isEmpty()) {
            sb.append(" = ").append(defaultValue);
        }
        return sb.toString();
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        ParamInfo paramInfo = (ParamInfo) o;
        return required == paramInfo.required &&
                Objects.equals(name, paramInfo.name) &&
                Objects.equals(type, paramInfo.type) &&
                Objects.equals(defaultValue, paramInfo.defaultValue) &&
                Objects.equals(annotation, paramInfo.annotation);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name, type, required, defaultValue, annotation);
    }

    @Override
    public String toString() {
        return "ParamInfo{" +
                "name='" + name + '\'' +
                ", type='" + type + '\'' +
                ", required=" + required +
                ", defaultValue='" + defaultValue + '\'' +
                ", annotation='" + annotation + '\'' +
                '}';
    }
}